<?php
namespace Admin\Controller;
use Think\Controller;

class AdminroleController extends Controller {
    public function index(){
        
    	$role = M('auth_group')->select();

    	/*foreach ($role as $k => $v) {
    		foreach ($v['rules'] as $value) {
    			foreach ($title as $key => $value) {
	    			# code...
	    		}
    		}
    	}
*/

    	/*$sql = "select t1.*,t2.title from auth_group t1 left join auth_rule t2 on t2.id=t1.rules";

    	$res = M()->query($sql);*/
/*
    	foreach ($role as $v) {
    		$arr = split(',',  $v['rules']);
            for($i=0;$i<$arr;$i++){
                foreach ($title as $value) {
                    if($arr[$i]==$value['id']);
                    
                }
            }
    	}

    	var_dump($arr);exit;*/

        $sql = "select t1.gname,t2.title from ruletogroup t1 left join auth_rule t2 on t1.rid=t2.id";

        $rules = M()->query($sql);

        foreach ($role as $k => $v) {
            foreach ($rules as $key => $value) {
                if($v['title']==$value['gname']){
                    $role[$k]['content'][]=$value['title'];
                }
            }
        }

        /*var_dump($role);exit;*/

    	$this->assign('role',$role);

        $this->display();
    }

}

?>